package com.cn.unarmed.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * 自定义曲线面积图
 */
public class CurveAreaView extends View {

    private Context context;

    //申明一支画笔
    private Paint paint;

    public CurveAreaView(Context context){
        super(context);
        this.context = context;
    }

    public CurveAreaView(Context context, AttributeSet attributeSet){
        super(context,attributeSet);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//      此方法获取组件设置的布局的宽高
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//      获取view的画布对组件进行绘制
        paint = new Paint();
        //设置画笔的颜色为黑色
        paint.setColor(Color.BLACK);
        //画一个小圆
        canvas.drawText("画圆",10,20,paint);
        canvas.drawCircle(60,20,10,paint);//小圆
        canvas.drawCircle(120,20,20,paint);//大圆
        //paint设置抗锯齿
        paint.setAntiAlias(true);

        canvas.drawText("画线",10,60,paint);
        paint.setColor(Color.GREEN);//将画笔颜色改为绿色
        canvas.drawLine(60,40,100,40,paint);//直线
        canvas.drawLine(110,40,180,80,paint);//斜线
    }
}
